package cn.wolfcode.crm.util;

import cn.wolfcode.crm.mapper.BaseMapper;
import cn.wolfcode.crm.query.QueryObject;

import java.util.List;

/**
 * @author 丧彪
 */
public class PageUtils {
	private PageUtils() {
	}

	/**
	 * 分页或高级查询
	 * @param <T>
	 */
	public static <T> PageResult query(QueryObject qo,BaseMapper<T> mapper) {

		// 1:查总条数
		int total = mapper.queryForCount(qo);
		System.out.println(qo.getClass());
		if (total == 0) {
			return PageResult.EMPTY_RESULT;
		}
		// 2:查分页数据
		List<T> rows = mapper.queryForList(qo);

		return new PageResult(total, rows);
	}
}
